#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>

#define MAX_N 30
#define MAX_NAME_LEN 21

struct Person {
    char name[MAX_NAME_LEN];
    int password;
    int out;
};

int main() {
    struct Person people[MAX_N];
    int N, i, j, M;

    // Input
    scanf("%d", &N);
    for (i = 0; i < N; ++i) {
        scanf("%s %d", people[i].name, &people[i].password);
        people[i].out = 0;
    }
    scanf("%d", &M);

    // Game logic
    int count = 0;
    int current = 0;
    while (count < N) {
        for (i = 0; i < M; ++i) {
            do {
                current = (current + 1) % N;
            } while (people[current].out);
        }
        printf("%s ", people[current].name);
        people[current].out = 1;
        M = people[current].password;
        ++count;
    }

    return 0;
}

